
#include "stdafx.h"
#include "TestList.h"
#include <string>

#include "DbgTrace.h"
#include "CmString.h"
#include "CmMiniDumper.h"
#include "CmUtil.h"

#include "DbgAssert.h"
#include "DbgCommon.h"

//TestLOG
#include "CommonLib.h"
#include "Singleton.h"
#include "CmThread.h"
#include "FileLogThread.h"
#include "CmLog.h"

#include "TestLogicPtr.h"

void TestLOG()
{
	CREATE_SINGLETON(Thread::ThreadPool);
	CREATE_SINGLETON(LogThreadSys);


	CmLog log;
	log.Load();
	log.SetLogFlag( CmLog::eLOG_TARGET_DBG_WND|CmLog::eLOG_TARGET_FILE );
	for(int i=0;i<10000;++i)
		log.PrintLogFormat(0, TEXT("test\n") );

	DESTROY_SINGLETON(LogThreadSys);
	DESTROY_SINGLETON(Thread::ThreadPool);
}

void TestRandom()
{
	//g_RandomPools.ResetSeed();

	CmRandom::Srand( ::timeGetTime() );
	for(int i=0;i<10; ++i)
	{
		//int result = g_RandomPools.RandMinMax(300, 400);
		int result = CmRandom::RandMinMax(300, 400);
		CmTRACE( L"%d \n", result);
	}

	//CmRandom::RandMinMaxf(0.f, 20.f);
	for(int i=0;i<10; ++i)
	{
		//double fResult = g_RandomPools.Randf();
		float fResult = CmRandom::RandMinMaxf(0.f, 20.f);
		//double fResult = g_RandomPools.RandMinMaxf( 1.f, 20.f);

		CmTRACE( L"%f \n", fResult);
	}
}

void TestString()
{
	CmWString str( L"Test");
	int testI=100;
	str.Format( L"%s %d", str.c_str(), testI );

	CmTRACE( L"%s", str.c_str());
}

//<< TestException
void _PurecallHandler()
{
	::RaiseException( EXCEPTION_ACCESS_VIOLATION, 0, 0, NULL);
}

void _InvalidParameterHander(const wchar_t* pExpression, const wchar_t* funtion, const wchar_t* f, unsigned int line, uintptr_t reserved)
{
	UNREFERENCED_PARAMETER(pExpression);
	UNREFERENCED_PARAMETER(funtion);
	UNREFERENCED_PARAMETER(f);
	UNREFERENCED_PARAMETER(line);
	UNREFERENCED_PARAMETER(reserved);
	::RaiseException( EXCEPTION_ACCESS_VIOLATION, 0, 0, NULL);
}

void TestException()
{
	UTIL::SetWorkingDirectory();
	Exception::MiniDumper(nullptr);
	_set_purecall_handler(_PurecallHandler);
	_set_invalid_parameter_handler(_InvalidParameterHander);

	//do Exception 
	int* test=nullptr;
	*test = 123;
}
//>> TestException

void TestAssert()
{
	int i=123;
	CmASSERT(i==122);
}

void TestPrtFunc()
{
	ProcessFactory PF1;
	PF1.Create(eTEST_1);
	PF1.Register();
	PF1.Excute(eMATH_ADD, 1,2,3);
	PF1.Excute(eSTRING_1, 1,2,3);
	PF1.Destroy();

	ProcessFactory PF2;
	PF2.Create(eTEST_2);
	PF2.Register();
	PF2.Excute(eMATH_ADD, 1,2,3);
	PF2.Excute(eSTRING_1, 1,2,3);
	PF2.Destroy();

	ProcessFactory PF3;
	PF3.Create(eTEST_3);
	PF3.Register();
	PF3.Excute(eMATH_ADD, 1,2,3);
	PF3.Excute(eSTRING_1, 1,2,3);
	PF3.Destroy();
}
